package com.openai.chatgpt.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;


@Schema(description = "统一响应对象")
@Data
public class AjaxResult<T> implements Serializable {

    private static final long serialVersionUID = 7337293201809451832L;

    public static final String CODE_TAG = "code";

    public static final String DATA_TAG = "data";

    public static final String MSG_TAG = "msg";

    @Schema(description = "状态码")
    private int code;

    @Schema(description = "返回内容")
    private String msg;

    @Schema(description = "返回数据")
    private T data;


    public AjaxResult() {

    }

    public AjaxResult(int code, String msg) {
        this();
        this.code = code;
        this.msg = msg;
    }

    public AjaxResult(int code, String msg, T data) {
        this();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult success() {
        return AjaxResult.success("操作成功");
    }

    public static AjaxResult success(String msg) {
        return AjaxResult.data(msg, null);
    }

    public static <T> AjaxResult data(T data) {
        return AjaxResult.data("操作成功", data);
    }

    public static <T> AjaxResult<T> data(String msg, T data) {
        return (AjaxResult<T>) new AjaxResult(200, msg, data);
    }


    public static AjaxResult error(String msg) {
        return AjaxResult.error(msg, null);
    }

    public static AjaxResult error(String msg, Object data) {
        return new AjaxResult(500, msg, data);
    }

    public static AjaxResult error(int code, String msg) {
        return new AjaxResult(code, msg, null);
    }

}
